<?php
// +----------------------------------------------------------------------
// | HKCMS
// +----------------------------------------------------------------------
// | Copyright (c) 2012-2019 http://www.hkcms.cn, All rights reserved.
// +----------------------------------------------------------------------
// | Author: 广州恒企教育科技有限公司 <admin@hkcms.cn>
// +----------------------------------------------------------------------

namespace app\api\controller;

use common\controller\Hkcms;

class Baseinfo extends Hkcms
{
    /**
     * 获取分类模板
     * @return string
     */
    public function categoryTpl()
    {
        $input = $this->request->only(['name','item']);
        if (empty($input['name'])) {
            return '必要参数为空';
        }

        $tree = new \libs\util\Tree();
        $tree->icon = array('&nbsp;&nbsp;&nbsp;│ ', '&nbsp;&nbsp;&nbsp;├─ ', '&nbsp;&nbsp;&nbsp;└─ ');
        $tree->nbsp = '&nbsp;&nbsp;&nbsp;';

        $categorys = array();
        $categorysList = hk_cache('Category');

        foreach ($categorysList as $r) {
            $r = getCategory($r['catid']);
            if ($r['type'] != 0)
                continue;
            $r['modelname'] = $this->model[$r['modelid']]['name'];
            $r['style'] = !empty($input['item']) && $input['item']==$r['catid'] ? 'selected' : '';
            $categorys[$r['catid']] = $r;
        }

        $str = "<option \$style value='\$id'>\$spacer\$catname</option>";

        $tree->init($categorys);
        $categorys = $tree->get_tree(0, $str);

        $html = "<select name='".$input['name']."'>$categorys</select>";
        return $html;
    }
}